﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class appleader_projects_new : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["organizationid"] != null)
            {
                DataTable dt_model = MasApp.BLL.Search.SearchAvailModelIDandName(int.Parse(Session["organizationid"].ToString()));
                ddl_model.DataTextField = "modelname";
                ddl_model.DataValueField = "modelid";
                ddl_model.DataSource = dt_model;
                ddl_model.DataBind();

                DataTable dt_method = MasApp.BLL.Search.SearchAvailMethodIDandName(int.Parse(Session["organizationid"].ToString()));
                ddl_method.DataTextField = "methodname";
                ddl_method.DataValueField = "methodid";
                ddl_method.DataSource = dt_method;
                ddl_method.DataBind();

                tb_projectname.Focus();
                starttime.Attributes.Add("readonly", "true");
                endtime.Attributes.Add("readonly", "true");
            }
            else
            {
                Response.Redirect("~/default.aspx");
            }
            Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "sub", "return confirm('请确认填写的信息？')");
        }
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {

        MasApp.Model.project pro = new MasApp.Model.project();
        pro.Organizationid = int.Parse(Session["organizationid"].ToString());
        pro.Projectname = tb_projectname.Text;
        pro.Starttime = Convert.ToDateTime(starttime.Text);
        pro.Endtime = Convert.ToDateTime(endtime.Text);
        
        if (pro.Starttime>pro.Endtime)
        {
            MasApp.BLL.ResponseHelper.alert("开始日期不能大于结束日期!");
        }
        else
        {
            pro.Creator = Session["username"].ToString();
            pro.Description = tb_description.Text;
            pro.Methodid = int.Parse(ddl_method.SelectedValue);
            pro.Modelid = int.Parse(ddl_model.SelectedValue);
            pro.Organizationid = int.Parse(Session["organizationid"].ToString());
            if (rb_direct.Checked)
            {
                pro.Weighttype = "直接赋权";
            }
            else
            {
                pro.Weighttype = "序关系法";
            }


            int projectid = MasApp.BLL.reg.RegProject(pro);
            if (projectid > 0)
            {
                MasApp.BLL.ResponseHelper.alert("恭喜你，项目添加成功！", "editlist.aspx");
            }
            else
            {
                MasApp.BLL.ResponseHelper.alert("出错了！添加失败！", "new.aspx");
            }
        }
        
    }
}